package com.redpack.redpost.struts.action.admin;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.redpack.redpost.struts.form.admin.faqsForm;
import com.redpack.redpost.util.dao.adminDAO;
import com.redpack.redpost.util.to.faqsTo;
import com.redpack.redpost.util.to.generalUtil;

public class editarfaqs extends Action {
	
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form, 
			HttpServletRequest request, 
			HttpServletResponse response) throws Exception {
		
		boolean logginVal = generalUtil.isLoggedInAdmin(request);
		if(logginVal!=true){
			return mapping.findForward("noLogin") ;
		}
		
		faqsForm f = (faqsForm)form;
		
		String[][] idiomas = generalUtil.obtieneIdiomas();
		
		request.setAttribute("idiomas", idiomas);
		
		if( f != null ){
			if( f.getAcc().equals("2") ){
				adminDAO.eliFaq(f.getCve_faq());
			}
			
			if( f.getAcc().equals("1") ){
		
				faqsTo faq_info = adminDAO.getFaq( f.getCve_faq() );
				
				request.setAttribute("pregunta_sel", faq_info.getPregunta());
				request.setAttribute("cve_faq", ""+faq_info.getCve_faq());
				request.setAttribute("respuesta_sel", ""+faq_info.getRespuesta());
				request.setAttribute("idioma_sel", ""+faq_info.getIdioma());
				
				return mapping.findForward("edit") ;
			}
		}
		
		List faqs = adminDAO.getFaqsAdmon();
		request.setAttribute("faqs", faqs);
		
		return mapping.findForward("success") ;
	}

}